home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 22 / 4 / DISK2247.ZIP / CBASE101.ZIP / LSEQ101.ZIP / LSEQ.H < prev    next >
Text File  |  1990-06-20  |  5KB  |  150 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lseq.h    1.4 - 90/06/20" */
  5.  
  6. /*man---------------------------------------------------------------------------
  7. NAME
  8.      lseq - linked sequential file management library
  9.  
  10. SYNOPSIS
  11.      #include <lseq.h>
  12.  
  13. DESCRIPTION
  14.      The lseq library consists of a set of routines for the creation
  15.      and manipulation of doubly-linked sequential files.
  16.  
  17.      lseq uses the blkio library for file access and buffering.
  18.      Therefore bexit should be used in place of exit when using lseq.
  19.  
  20. SEE ALSO
  21.      lsclose, lscreate, lscursor, lsdelcur, lsfirst, lsgetcur,
  22.      lsgetlck, lsgetr, lsgetrf, lsinsert, lslast, lslock, lsnext,
  23.      lsopen, lsprev, lsputr, lsputrf, lsreccnt, lsrecsize, lssearch,
  24.      lssetbuf, lssetcur, lssetvbuf, lssync.
  25.  
  26. ------------------------------------------------------------------------------*/
  27. #ifndef LSEQ_H        /* prevent multiple includes */
  28. #define LSEQ_H
  29.  
  30. #include <blkio.h>
  31. /*#include <stddef.h>*/
  32.  
  33. /* constants */
  34. #define LSOPEN_MAX    BOPEN_MAX    /* max # lseqs open at once */
  35. #define LSBUFCNT    ((size_t)10)    /* default # of records to buffer */
  36.  
  37. /* macro to calculate buffer size needed by an lseq */
  38. #define LSBUFSIZ(RECSIZE, BUFCNT) ((size_t)(                \
  39.     sizeof(lshdr_t) +                        \
  40.     (BUFCNT) * (offsetof(lsrec_t, recbuf) + (RECSIZE)        \
  41. ))
  42.  
  43. /* type definitions */
  44. typedef bpos_t    lspos_t;    /* lseq position */
  45. #ifdef AC_PROTO
  46. typedef int (*lscmp_t)(const void *p1, const void *p2, size_t n);
  47. #else
  48. typedef int (*lscmp_t)();
  49. #endif
  50.  
  51. typedef struct {        /* lseq record */
  52.     lspos_t next;        /* next record in list */
  53.     lspos_t prev;        /* previous record in list */
  54.     void *recbuf;        /* record contents */
  55. } lsrec_t;
  56.  
  57. typedef struct {        /* lseq file header */
  58.     bpos_t flh;        /* position of free list head */
  59.     size_t recsize;        /* record size */
  60.     int flags;        /* flags */
  61.     lspos_t first;        /* position of first record */
  62.     lspos_t last;        /* position of last record */
  63.     unsigned long reccnt;    /* number records currently in lseq */
  64. } lshdr_t;
  65.  
  66. typedef struct {        /* lseq control structure */
  67.     lshdr_t lshdr;        /* file header */
  68.     BLKFILE *bp;        /* block file */
  69.     int flags;        /* status flags */
  70.     lspos_t clspos;        /* current lseq position */
  71.     lsrec_t *clsrp;        /* current record */
  72. } lseq_t;
  73.  
  74. /* function declarations */
  75. #ifdef AC_PROTO
  76. int        lsclose(lseq_t *lsp);
  77. int        lscreate(const char *filename, size_t recsize);
  78. int        lsdelcur(lseq_t *lsp);
  79. int        lsfirst(lseq_t *lsp);
  80. int        lsgetcur(lseq_t *lsp, lspos_t *lsposp);
  81. int        lsgetlck(lseq_t *lsp);
  82. int        lsgetr(lseq_t *lsp, void *buf);
  83. int        lsgetrf(lseq_t *lsp, size_t offset, void *buf, size_t bufsize);
  84. int        lsinsert(lseq_t *lsp, const void *buf);
  85. int        lslast(lseq_t *lsp);
  86. int        lslock(lseq_t *lsp, int ltype);
  87. int        lsnext(lseq_t *lsp);
  88. lseq_t *    lsopen(const char *filename, const char *type);
  89. int        lsprev(lseq_t *lsp);
  90. int        lsputr(lseq_t *lsp, const void *buf);
  91. int        lsputrf(lseq_t *lsp, size_t offset, const void *buf,
  92.             size_t bufsize);
  93. int        lssearch(lseq_t *lsp, size_t offset, const void *buf,
  94.             size_t bufsize, lscmp_t cmp);
  95. int        lssetbuf(lseq_t *lsp, void *buf);
  96. int        lssetcur(lseq_t *lsp, const lspos_t *lsposp);
  97. int        lssetvbuf(lseq_t *lsp, void *buf, size_t bufcnt);
  98. int        lssync(lseq_t *lsp);
  99. #else
  100. int        lsclose();
  101. int        lscreate();
  102. int        lsdelcur();
  103. int        lsfirst();
  104. int        lsgetcur();
  105. int        lsgetlck();
  106. int        lsgetr();
  107. int        lsgetrf();
  108. int        lsinsert();
  109. int        lslast();
  110. int        lslock();
  111. int        lsnext();
  112. lseq_t *    lsopen();
  113. int        lsprev();
  114. int        lsputr();
  115. int        lsputrf();
  116. int        lssearch();
  117. int        lssetbuf();
  118. int        lssetcur();
  119. int        lssetvbuf();
  120. int        lssync();
  121. #endif    /* #ifdef AC_PROTO */
  122.  
  123. /* macros */
  124. #define    lscursor(LSP)    ((void *)(                    \
  125.     (LSP)->clspos == NIL ? NULL : ((char *)NULL + 1)        \
  126. ))
  127. #define    lsreccnt(LSP)    ((LSP)->lshdr.reccnt)
  128. #define    lsrecsize(LSP)    ((LSP)->lshdr.recsize)
  129.  
  130. /* lock types */
  131. #define LS_UNLCK    (0)    /* unlock */
  132. #define LS_RDLCK    (1)    /* read lock */
  133. #define LS_WRLCK    (2)    /* write lock */
  134. #define LS_RDLKW    (3)    /* read lock, wait */
  135. #define LS_WRLKW    (4)    /* write lock, wait */
  136.  
  137. /* lseq error codes */
  138. #define LSEOS        (-20)    /* start of lseq error code domain */
  139. #define LSEMFILE    (LSEOS - 1)    /* too many open lseqs */
  140. #define LSECORRUPT    (LSEOS - 2)    /* lseq is corrupt */
  141. #define LSENOPEN    (LSEOS - 3)    /* lseq not open */
  142. #define LSENBUF        (LSEOS - 4)    /* buffering is off */
  143. #define LSELOCK        (LSEOS - 5)    /* incorrect lock type */
  144. #define LSENREC        (LSEOS - 6)    /* no record */
  145. #define LSEBOUND    (LSEOS - 7)    /* record boundary error */
  146. #define LSEEOF        (LSEOS - 8)    /* past end of file */
  147. #define LSEPANIC    (LSEOS - 9)    /* internal lseq error */
  148.  
  149. #endif        /* #ifndef LSEQ_H */
  150.